﻿using System;
using System.Windows.Controls;
using LaserTag.Module.AForgeModule.ViewModels;
using Microsoft.Practices.Composite;

namespace LaserTag.Module.AForgeModule.Views
{
    public partial class AForgeVideoProcessorSetupView : UserControl, IAForgeVideoProcessorSetupView, IActiveAware
    {
        private bool m_isActive;
        public event EventHandler IsActiveChanged;
        private IAForgeVideoProcessorSetupViewModel m_viewModel;

        /// <summary>
        /// The constructor used by dependency injection.
        /// </summary>
        public AForgeVideoProcessorSetupView()
        {
            InitializeComponent();
        }

        #region IAForgeVideoProcessorSetupView Members

        public void SetViewModel(IAForgeVideoProcessorSetupViewModel viewModel)
        {
            m_viewModel = viewModel;
            DataContext = viewModel;
        }

        #endregion

        #region IActiveAware Members

        public bool IsActive
        {
            get { return m_isActive; }
            set
            {
                m_isActive = value;
                m_viewModel.ViewActivated = value;
                InvokeIsActiveChanged();
            }
        }

        private void InvokeIsActiveChanged()
        {
            var e = new EventArgs();
            EventHandler changed = IsActiveChanged;
            if (changed != null) changed(this, e);
        }

        #endregion
    }
}
